package com.neoCalf.neoFile.controller;

import com.neoCalf.neoCommon.model.R;
import com.neoCalf.neoCommon.model.dto.UploadDto;
import com.neoCalf.neoCommon.model.vo.UpLoadImageVo;
import com.neoCalf.neoFile.service.UpLoadService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


/**
 * @author 小牛
 * @version 1.0
 * @description TODO
 * @date 2025/4/15 22:33
 */
@RestController
@RequestMapping("/upload")
@Validated
public class UpLoadController {
    @Resource
    private UpLoadService upLoadService;


    @PostMapping("/image")
    public R<UpLoadImageVo> uploadImage(HttpServletRequest request, @NotNull UploadDto uploadDto) {
        String userId = request.getHeader("userId");
        UpLoadImageVo upLoadImageVo = upLoadService.uploadImage(userId, uploadDto);
        return R.ok(upLoadImageVo);
    }

    @DeleteMapping("/image/delete")
    public R<String> deleteImage(@RequestParam("url") @NotEmpty String url) {
        upLoadService.deleteImage(url);
        return R.ok();
    }
}